Skip to content

Method: getProperties(NamedResource, URI, boolean)

1: /*
2: * JOPA
3: * Copyright (C) 2024 Czech Technical University in Prague
4: *
5: * This library is free software; you can redistribute it and/or
6: * modify it under the terms of the GNU Lesser General Public
7: * License as published by the Free Software Foundation; either
8: * version 3.0 of the License, or (at your option) any later version.
9: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library.
17: */
18: package cz.cvut.kbss.ontodriver.owlapi;
19:
20: import cz.cvut.kbss.ontodriver.Properties;
21: import cz.cvut.kbss.ontodriver.exception.OntoDriverException;
22: import cz.cvut.kbss.ontodriver.model.Assertion;
23: import cz.cvut.kbss.ontodriver.model.Axiom;
24: import cz.cvut.kbss.ontodriver.model.NamedResource;
25: import cz.cvut.kbss.ontodriver.model.Value;
26: import cz.cvut.kbss.ontodriver.owlapi.exception.OwlapiDriverException;
27: import cz.cvut.kbss.ontodriver.owlapi.util.Procedure;
28:
29: import java.net.URI;
30: import java.util.Collection;
31: import java.util.Map;
32: import java.util.Objects;
33: import java.util.Set;
34:
35: import static cz.cvut.kbss.ontodriver.util.ErrorUtils.getNPXMessageSupplier;
36:
37: public class OwlapiProperties implements Properties {
38:
39: private final OwlapiAdapter adapter;
40:
41: private final Procedure beforeCallback;
42: private final Procedure afterChangeCallback;
43:
44: public OwlapiProperties(OwlapiAdapter adapter, Procedure beforeCallback, Procedure afterChangeCallback) {
45: this.afterChangeCallback = afterChangeCallback;
46: this.beforeCallback = beforeCallback;
47: this.adapter = adapter;
48: }
49:
50: @Override
51: public Collection<Axiom<?>> getProperties(NamedResource individual, URI context, boolean includeInferred)
52: throws OntoDriverException {
53: Objects.requireNonNull(individual, getNPXMessageSupplier("individual"));
54: beforeCallback.execute();
55: return adapter.getPropertiesHandler().getProperties(individual, includeInferred);
56: }
57:
58: @Override
59: public void addProperties(NamedResource individual, URI context, Map<Assertion, Set<Value<?>>> properties)
60: throws OntoDriverException {
61: ensureValidity(individual, properties);
62: if (!properties.isEmpty()) {
63: adapter.getPropertiesHandler().addProperties(individual, properties);
64: }
65: afterChangeCallback.execute();
66: }
67:
68: private void ensureValidity(NamedResource individual, Map<Assertion, Set<Value<?>>> properties)
69: throws OwlapiDriverException {
70: Objects.requireNonNull(individual, getNPXMessageSupplier("individual"));
71: Objects.requireNonNull(properties, getNPXMessageSupplier("properties"));
72: beforeCallback.execute();
73: }
74:
75: @Override
76: public void removeProperties(NamedResource individual, URI context, Map<Assertion, Set<Value<?>>> properties)
77: throws OntoDriverException {
78: ensureValidity(individual, properties);
79: if (!properties.isEmpty()) {
80: adapter.getPropertiesHandler().removeProperties(individual, properties);
81: }
82: afterChangeCallback.execute();
83: }
84: }